﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Quexcel.OpenXML
{
    internal class ConnectionStringLoader
    {
        private string connectionString;
        private Dictionary<string, string> connectionStringParams;

        public ConnectionStringLoader(string connectionString)
        {
            this.connectionString = connectionString;
            connectionStringParams = new Dictionary<string, string>(4);

            foreach (string param in connectionString.Split(';'))
            {
                if (!String.IsNullOrEmpty(param.Trim()))
                {
                    string name = param.Split('=')[0].Trim();
                    string value = param.Split('=')[1].Trim();

                    connectionStringParams.Add(name, value);
                }
            }
        }

        public string this[string name]
        {
            get
            {
                if (connectionStringParams.ContainsKey(name))
                    return connectionStringParams[name];
                else
                    return null;
            }
        }
    }

    internal struct ConnectionStringFields
    {
        public const string Database = "database";
        public const string UserName = "username";
        public const string Password = "password";
        public const string InitialCatalog = "initialCatalog";
    }
}
